/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "ola_negotiation.h"

#include <stdlib.h>

#include "ola_error.h"
#include "ola_device_model.h"
#include "ola_log.h"
#include "ola_jpake.h"
#include "ola_pecdh.h"
#include "ola_provisioning.h"
#include "ola_sdk.h"
#if defined(SUPPORT_SPEKE_1) || defined(SUPPORT_SPEKE_3)
#include "ola_speke.h"
#endif

const OlaNegotiationHook *OlaGetNegotiationHooks(void)
{
    const OlaNegotiationHook *hook = NULL;
    const OlaNetCfgParam *cfgParam = OlaGetNetCfgParam();
    if (cfgParam == NULL) {
        OlaLogError("get init param failed");
        return hook;
    }
    OlaSecNegotiationType negoType = cfgParam->negoType;
    OlaLogInfo("nego Type: [%d]", negoType);
    if ((negoType < OLA_SEC_NEGO_TYPE_SPEKE) || (negoType > OLA_SEC_NEGO_TYPE_PECDH)) {
        OlaLogError("invalid nego type");
        return hook;
    }
    switch (negoType) {
#if defined(SUPPORT_SPEKE_1) || defined(SUPPORT_SPEKE_3)
        case OLA_SEC_NEGO_TYPE_SPEKE:
            hook = OlaGetSpekeNegoHooks();
            break;
#endif
        case OLA_SEC_NEGO_TYPE_JPAKE:
            hook = OlaGetJpakeNegoHooks();
            break;
        case OLA_SEC_NEGO_TYPE_PECDH:
            hook = OlaGetPecdhNegoHooks();
            break;
        default:
            break;
    }
    return hook;
}
